<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	if($_RQ['gamename']){
		$this->session('gamename',$_RQ['gamename']);
	}
	$gamename=$this->session('gamename');
	$params=array('pid'=>0);
	$params['gamename']=$gamename;
	$gametitle=$this->allgames2[$gamename];
	$return['params']=$params;
	$return['gametitle']=$gametitle;
	$return['p_group']=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	set_html('title',$gametitle.'模板');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['pid'] && $_RQ['pid']!='all'){
		$params['groupid']=intval($_RQ['pid']);
	}
	if($_RQ['gamename']){
		$params['gamename']=$_RQ['gamename'];
	}
	if($_RQ['keyword']){
		$params['title like']='%'.$_RQ['keyword'].'%';
		$return['params']['keyword']=$_RQ['keyword'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_merch_game_item_tpl',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['url']='/tpl_look//id='.$item['id'];
			$item['logo'] = tomedia($item['logo']);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		}
	}
	
	$return['list']=$list;
	exi($return);
}

if($_RQ['op']=='del'){	
	if(!$_RQ['id']){
		exi('作品不存在哦！','error');
	}
	
	pdo_delete('jy_merch_game_item_tpl',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除成功！');

}

if($_RQ['op']=='open'){
	$postdata=get_postdata();
	$id=$postdata['id'];
	if(!$id){
		exi('作品不存在哦！'.$id,'error');
	}
	$isshow=pdo_getcolumn('jy_merch_game_item_tpl',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'isshow');
	if($isshow){
		pdo_update('jy_merch_game_item_tpl',array('isshow'=>0),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		pdo_update('jy_merch_game_item_tpl',array('isshow'=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}
	exi('操作成功');
}